load("//tools:defaults.bzl", "angular_jasmine_test", "js_binary", "js_run_binary", "ng_project", "ng_web_test_suite", "ts_project")

package(default_visibility = ["//visibility:private"])

TEST_FILES = glob(
    ["*.ts"],
    exclude = ["authoring_test_compiler.ts"],
)

TEST_DEPS = [
    "//packages/core:core",
    "//packages/core/rxjs-interop:rxjs-interop",
    "//packages/core/testing:testing",
    "//packages/platform-browser:platform-browser",
    "//packages/core/primitives/signals:signals",
    "//:node_modules/rxjs",
    "//packages/core/test/animation_utils",
    "//packages/private/testing",
]

ts_project(
    name = "test_compiler_lib",
    testonly = True,
    srcs = ["authoring_test_compiler.ts"],
    deps = [
        "//:node_modules/typescript",
        "//packages/compiler-cli/private",
    ],
)

js_binary(
    name = "test_compiler",
    testonly = True,
    data = [
        ":test_compiler_lib",
        "//packages:package_json",
    ],
    entry_point = ":authoring_test_compiler.js",
)

js_run_binary(
    name = "processed_test_sources",
    testonly = True,
    srcs = TEST_FILES,
    outs = ["transformed_%s" % file for file in TEST_FILES],
    args = ["../../../$(@D)"] + ["$(rootpath %s)" % file for file in TEST_FILES],
    tool = ":test_compiler",
)

ts_project(
    name = "test_jit_lib",
    testonly = True,
    srcs = ["transformed_%s" % file for file in TEST_FILES],
    deps = TEST_DEPS,
)

ng_project(
    name = "test_lib",
    testonly = True,
    srcs = TEST_FILES,
    deps = TEST_DEPS,
)

angular_jasmine_test(
    name = "test",
    data = [
        ":test_lib",
    ],
)

angular_jasmine_test(
    name = "test_jit",
    data = [
        ":test_jit_lib",
    ],
)

ng_web_test_suite(
    name = "test_web",
    deps = [
        ":test_lib",
    ],
)

ng_web_test_suite(
    name = "test_jit_web",
    deps = [
        ":test_jit_lib",
    ],
)
